package com.ydjk.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ydjk.common.utils.pageData.PageData;
import com.ydjk.domain.JkPushTemplateItem;
import com.ydjk.domain.JkTemplate;
import com.ydjk.service.IJkTemplateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ydjk.common.annotation.Log;
import com.ydjk.common.core.controller.BaseController;
import com.ydjk.common.core.domain.AjaxResult;
import com.ydjk.common.enums.BusinessType;

import com.ydjk.common.utils.poi.ExcelUtil;
import com.ydjk.common.core.page.TableDataInfo;

/**
 * 模版Controller
 * 
 * @author ruoyi
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/system/template")
public class JkTemplateController extends BaseController
{
    @Autowired
    private IJkTemplateService jkTemplateService;

    /**
     * 查询模版列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(JkTemplate jkTemplate)
    {
        startPage();
        List<JkTemplate> list = jkTemplateService.selectJkTemplateList(jkTemplate);
        return getDataTable(list);
    }


    /**
     * 查询模版列表
     */

    @GetMapping("/listAllTemplateItem/{id}")
    public TableDataInfo listAllTemplateItem(@PathVariable("id")String id)
    {
        List<PageData> list = jkTemplateService.listAllTemplateItem(id);
        return getDataTable(list);
    }

    /**
     * 导出模版列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:export')")
    @Log(title = "模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JkTemplate jkTemplate)
    {
        List<JkTemplate> list = jkTemplateService.selectJkTemplateList(jkTemplate);
        ExcelUtil<JkTemplate> util = new ExcelUtil<JkTemplate>(JkTemplate.class);
        util.exportExcel(response, list, "模版数据");
    }

    /**
     * 获取模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(jkTemplateService.selectJkTemplateById(id));
    }

    /**
     * 新增模版
     */
    @PreAuthorize("@ss.hasPermi('system:template:add')")
    @Log(title = "模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JkTemplate jkTemplate)
    {
        return toAjax(jkTemplateService.insertJkTemplate(jkTemplate));
    }

    /**
     * 修改模版
     */
    @PreAuthorize("@ss.hasPermi('system:template:edit')")
    @Log(title = "模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JkTemplate jkTemplate)
    {
        return toAjax(jkTemplateService.updateJkTemplate(jkTemplate));
    }

    /**
     * 删除模版
     */
    @PreAuthorize("@ss.hasPermi('system:template:remove')")
    @Log(title = "模版", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(jkTemplateService.deleteJkTemplateByIds(ids));
    }
}
